home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / pmode / 386p_200 / picture.asm < prev    next >
Encoding:
Assembly Source File  |  1995-01-11  |  14.3 KB  |  597 lines

  1.  
  2.  
  3. ; Get/Put bitmaps (pictures)
  4. ; Compile/Put bitmaps with encoded transparency (sprites)
  5.        .386P
  6. code32 segment para public use32
  7.        assume cs:code32,ds:code32
  8. NOSMART
  9. NOJUMPS
  10. include 386video.inc
  11. include chtil.inc
  12. ; 1 nudget     = 4  pixel (plane aligned, one pixel for every plane)
  13. ; 1 big nudget = 16 pixel (plane aligned, four nudgets)
  14.  
  15. ; PIC format:
  16. ;            offset     size       name   description
  17. ;              0          2        WX     Width  of picture in BIG NUDGETS
  18. ;              2          2        WY     Height of picture in PIXELS
  19. ;              4       WX*WY*4     ----   First plane
  20.  
  21.     public _GetPic
  22.  
  23. ; reads picture from screen
  24. _GetPic:
  25.         ; in:
  26.         ; edi = pic dest
  27.         ; esi = scr source
  28.         ; eax = x in pixels
  29.         ; edx = y in pixels
  30.         ; ecx = x width  in nudgets
  31.         ; ebx = y height in pixels
  32.         ; out:
  33.         ; edi = ptr to end of picture
  34.         push eax
  35.         push ebx
  36.         push ecx
  37.         push edx
  38.         push esi 
  39.         push ebp
  40.          
  41.         add esi,[edx*4+_RowStart]
  42.         shl ebx,16
  43.         add esi,eax
  44.         mov bx,cx
  45.         mov edx,ecx
  46.         
  47.         mov [edi],ebx   ; registra ampiezza ed altezza
  48.         shl ecx,2       ; from nudgets to pixels
  49.         mov ebp,_ScrX
  50.         add edi,4       ; advance pointer 
  51.         shr ebx,16
  52.         sub ebp,ecx
  53. @getpicline:
  54.         mov ecx,edx
  55.         rep movsd
  56.         add esi,ebp
  57.         dec ebx
  58.         jne @getpicline
  59.         
  60.         ; edi = posizione DOPO la lettura della bitmap
  61.         pop ebp
  62.         pop esi
  63.         pop edx
  64.         pop ecx
  65.         pop ebx
  66.         pop eax
  67.         
  68.     ret
  69.  
  70.  
  71. BlastPut macro 
  72. @putpicline:
  73.         mov ecx,edx
  74.         rep movsd
  75.         add edi,ebp
  76.         dec ebx
  77.         jne @putpicline
  78.     endm
  79.  
  80. BlastRPut macro 
  81. @revpic:        
  82.         mov ecx,edx
  83. @revdword:        
  84.         mov eax,[esi]
  85.         rol  ax,8     ; one for the money
  86.         sub edi,4     ; (interleave this instruction)
  87.         rol  eax,16   ; two for the show
  88.         add esi,4     ; (interleave this instruction)
  89.         rol  ax,8     ; three get ready
  90.         dec ecx       ; interleave counter decrement
  91.         mov [edi],eax ; & let's rock!
  92.         jne @revdword
  93.         add edi,ebp
  94.         dec ebx
  95.         jne @revpic
  96.         endm
  97.  
  98.     public _PutPic
  99.  
  100. ; blits a picture to screen
  101. ; Warning! L' unica opzione valida e' LEFTRIGHT!
  102. _PutPic: 
  103.         ; edi = scr dest
  104.         ; esi = pic ptr
  105.         ; eax =  x in pixels
  106.         ; edx =  y in pixels
  107.         ; bl  =  blit mode flag    1=reverse left-right
  108.         pushad
  109.         add edi,[edx*4+_RowStart]
  110.         xor edx,edx
  111.         add edi,eax
  112.         and bl,LEFTRIGHT
  113.         jnz @pleftright
  114. @pnorm:
  115.         mov ebx,[esi]  ;width & height
  116.         mov dx,bx
  117.         shr ebx,16
  118.         mov ecx,edx
  119.         add esi,4
  120.         shl ecx,2  ; nudgets to pixels
  121.         mov ebp,_ScrX ; incremento di linea
  122.         sub ebp,ecx     ; correggi per avanzamento
  123.         
  124.         BlastPut 
  125. @pgottaut:
  126.         popad
  127.     ret
  128.  
  129. @pleftright:
  130.     ; LEFT TO RIGHT <--> RIGHT TO LEFT
  131. @noinc:
  132.         mov ebx,[esi]  ;width & height
  133.         mov dx,bx
  134.         add esi,4
  135.         shr ebx,16
  136.         mov ecx,edx
  137.         mov ebp,_ScrX ; incremento di linea
  138.         shl ecx,2  ; nudgets to pixels
  139.         add ebp,ecx     ; correggi per avanzamento        
  140.         
  141.         add edi,ecx  ; portati a fine linea
  142.  
  143.         BlastRPut 
  144.         popad
  145.         ret
  146.  
  147. ; An Spt (encoded SPriTe)
  148. ; has a dword header like a PICture
  149. ; offset size  significato
  150. ;      0    2  width in nudgets
  151. ;      2    2  height in pixels
  152. ; But the sprite data is contained into "packets"
  153. ; with transparent color ( color zero) coded in RLE format
  154.  
  155. ; RLE packet format:   [..] == .. is optional
  156. ; RLE_HEADER, [INCR 1byte ], [DATA_HEAD 0..3 byte ],[DATA_DWORD 0..n dwords]
  157.  
  158.  
  159. ;RLE_HEADER bit 0..1 = data_head lenght (0..3 BYTES)
  160. ;           bit    2 = dword data present (use bit 4..7), [DATA_DWORD] present
  161. ;           bit    3 = new line AFTER this blit
  162. ;           bit 4..7 = dword counter n  (0..15 DWORDS)
  163. ;
  164. ; a RLE_HEADER 00 (end of sprite) or 08 (newline)
  165. ; has no [INCR] field.
  166.  
  167. crunch macro
  168.         ; decode next packet
  169.         mov eax,[esi] ;read RLE_HEADER, INCR and 2 head bytes
  170.         mov dl,al   ; get jump index bit 0..3
  171.         mov cl,ah   ; get INCR count
  172.         and dl,0Fh  ; select jump index
  173.         add edi,ecx ; skip empty pixels
  174.         mov cl,al   ; get dword count bit 7..4
  175.         shr eax,16  ; get data into lower word
  176.         jmp  [edx*4+offset ETable] ; go to packet decoder
  177.         endm
  178.       
  179. ncrunch macro
  180.         ; newline & decode next packet
  181.         mov eax,[esi]
  182.         mov cl,ah
  183.         lea edi,[ebx+ebp*1] ; newline+line_start
  184.         mov dl,al
  185.         add edi,ecx ; INCR after newline
  186.         and dl,0Fh
  187.         mov cl,al  ; get dword count
  188.         add ebx,ebp  ; newline for line_start register too
  189.         shr eax,16
  190.         jmp [edx*4+ offset ETable] ; perform blit
  191.         endm
  192.  
  193. ; Hndl : Header, n== perform newline,d == dword data, l == data head lenght 
  194.  
  195. H000: ; END OF PLANE 
  196.         popad
  197.         ret        
  198.       
  199. H001:
  200.       stosb
  201.       add esi,3
  202.       crunch
  203.       
  204. H002: stosw
  205.       add esi,4
  206.       crunch
  207.       
  208. H003: add esi,4
  209.       stosw
  210.       movsb  ; copy last byte of DATA_HEAD
  211.       crunch
  212.       
  213. H010: shr ecx,4  ; get dword count
  214.       add esi,2
  215.       rep movsd
  216.       crunch      
  217.       
  218. H011:
  219.       shr ecx,4
  220.       add esi,3
  221.       stosb
  222.       rep movsd
  223.       crunch
  224.       
  225. H012: add esi,4
  226.       shr ecx,4
  227.       stosw
  228.       rep movsd
  229.       crunch
  230.       
  231. H013: add esi,4
  232.       shr ecx,4
  233.       stosw
  234.       movsb
  235.       rep movsd
  236.       crunch
  237.       
  238. H100: inc esi ; no [incr] field present
  239.       ncrunch
  240.       
  241. H101: add esi,3
  242.       stosb
  243.       ncrunch
  244.       
  245. H102: stosw
  246.       ncrunch
  247.       
  248. H103: add esi,4
  249.       stosw
  250.       movsb
  251.       ncrunch
  252.       
  253. H110: shr ecx,4
  254.       add esi,4
  255.       rep movsd
  256.       ncrunch
  257.  
  258. H111: add esi,3
  259.       shr ecx,4
  260.       stosb
  261.       rep movsd
  262.       ncrunch
  263.       
  264. H112: 
  265.       stosw
  266.       add esi,4
  267.       shr ecx,4
  268.       rep movsd
  269.       ncrunch
  270.       
  271. H113:
  272.       stosw
  273.       add esi,4
  274.       shr ecx,4
  275.       movsb
  276.       rep movsd
  277.       ncrunch
  278.       
  279.       align dword
  280. ETable: dd offset H000, offset H001, offset H002, offset H003
  281.         dd offset H010, offset H011, offset H012, offset H013    
  282.         dd offset H100, offset H101, offset H102, offset H103
  283.         dd offset H110, offset H111, offset H112, offset H113
  284.         align byte      
  285.  
  286. rcrunch macro
  287.         ; decode next packet
  288.         lodsd
  289.         mov dl,al   ; jump addr
  290.         mov cl,ah   ; skip count
  291.         and dl,0Fh  ; mask jump index
  292.         sub edi,ecx ; skip empty pixels
  293.         mov cl,al   ; dword count bit 7..4
  294.         shr eax,16  ; data into lower word
  295.         jmp  [edx*4+offset RETable] ; go to packet decoder
  296.         endm
  297.       
  298. reblast macro  @lup,@laap
  299. @lup:   lodsd
  300.         xchg al,ah
  301.         sub edi,4
  302.         rol eax,16
  303.         xchg al,ah
  304.         dec ecx
  305.         mov [edi],eax
  306.         je @laap
  307.         lodsd
  308.         xchg al,ah
  309.         sub edi,4
  310.         rol eax,16
  311.         xchg al,ah
  312.         dec ecx
  313.         mov [edi],eax
  314.         jne @lup
  315. @laap:
  316.         endm
  317.         
  318. rncrunch macro
  319.         ; newline & decode next packet
  320.         lodsd
  321.         mov cl,ah
  322.         lea edi,[ebx+ebp*1] ;newline
  323.         mov dl,al
  324.         sub edi,ecx
  325.         and dl,0Fh
  326.         mov cl,al
  327.         add ebx,ebp  ; perform newline on "line start" pointer
  328.         shr eax,16
  329.         jmp [edx*4+ offset RETable] ; perform blit
  330.         endm
  331.         
  332. rmovsb macro
  333.         mov [edi-1],al
  334.         dec edi
  335.        endm
  336.        
  337. rmovsw macro
  338.         sub edi,2
  339.         xchg al,ah
  340.         mov [edi],ax
  341.        endm       
  342.        
  343. rmovsbw macro
  344.         sub edi,3
  345.         xchg al,al
  346.         mov dl,[esi]
  347.         mov [edi+1],ax
  348.         mov [edi],dl
  349.        endm
  350.  
  351. ervsb macro
  352.         mov [edi-1],al
  353.         shr ecx,4
  354.         dec edi
  355.        endm
  356.        
  357. ervsw macro
  358.         sub edi,2
  359.         xchg al,ah
  360.         shr ecx,4
  361.         mov [edi],ax
  362.        endm       
  363.        
  364. ervsbw macro
  365.         sub edi,3
  366.         xchg al,al
  367.         mov dl,[esi]
  368.         shr ecx,4
  369.         mov [edi+1],ax
  370.         mov [edi],dl
  371.        endm
  372.         
  373.  
  374.  
  375. RH001: rmovsb
  376.        rcrunch
  377. RH002: rmovsw 
  378.        rcrunch
  379. RH003: rmovsbw
  380.        rcrunch
  381.       
  382. RH010: shr ecx,4
  383.        reblast  a0,aa0
  384.        rcrunch
  385.  
  386. RH011: ervsb
  387.        reblast  a1,aa1
  388.        rcrunch
  389.  
  390. RH012: ervsw
  391.        reblast  a2,aa2
  392.        rcrunch
  393.  
  394. RH013: ervsbw
  395.        reblast  a3,aa3
  396.        rcrunch
  397.       
  398. RH100:  sub esi,3 ; no [incr] field present
  399.         rncrunch
  400.       
  401. RH101: rmovsb             
  402.        rncrunch
  403.  
  404. RH102: rmovsw 
  405.        rncrunch
  406.  
  407. RH103: rmovsbw
  408.        rncrunch
  409.       
  410. RH110: shr ecx,4
  411.        reblast   a4,aa4
  412.        rncrunch      
  413. RH111: ervsb
  414.        reblast   a5,aa5
  415.        rncrunch
  416. RH112: ervsw
  417.        reblast   a6,aa6
  418.        rncrunch
  419. RH113: ervsbw
  420.        reblast   a7,aa7
  421.        rncrunch
  422.        
  423.        align dword
  424. RETable: dd offset  H000, offset RH001, offset RH002, offset RH003
  425.          dd offset RH010, offset RH011, offset RH012, offset RH013    
  426.          dd offset RH100, offset RH101, offset RH102, offset RH103
  427.          dd offset RH110, offset RH111, offset RH112, offset RH113
  428.        align byte  
  429.        
  430.  
  431.             
  432. ;-----------------------END OF RLE BLIT CODE------------------------
  433.  
  434.         public _PutSpt
  435.         
  436. _PutSpt:
  437.         ; edi = scr dest
  438.         ; esi = encoded sprite pic ptr
  439.         ; eax =  x in pixels
  440.         ; edx =  y in pixels
  441.         ; bl  =  drawing flags
  442.         pushad
  443.         add edi,[edx*4+_RowStart]
  444.         xor ecx,ecx
  445.         mov ebp,_ScrX
  446.         add edi,eax
  447.         and ebx,LEFTRIGHT ;test bit and reset ebx
  448.         jnz @esleftright
  449. @esnorm:
  450.         add esi,4
  451.         mov ebx,edi  ; set line start
  452.         xor edx,edx
  453.         crunch
  454.  
  455. @esleftright:
  456.         mov bx,[esi]  ;width
  457.         add esi,4
  458.         lea edi,[edi+ebx]  ; to end of line
  459.         xor edx,edx
  460.         mov ebx,edi
  461.         rcrunch
  462.         
  463.         align dword
  464. plane   dd 0
  465. y       dd 0
  466. yheight dd 0
  467. x       dd 0
  468.         align byte
  469.  
  470. NO_WAY  db 08   ; marker for "no smart newlines allowed"
  471.        
  472.         public _Pic2Spt
  473. _Pic2Spt:
  474.         ; converter from PIC bitmap format to SPT bitmap format        
  475.         ; 
  476.         ; ESI = pointer to PIC data
  477.         ; EDI = pointer to buffer for SPT data
  478.         ; returns:
  479.         ;  ESI = end of PIC data
  480.         ;  EDI = pointer to end of SPT bitmap data
  481.         ;        If PIC data is too big, EDI is equal to its initial value +2
  482.         push eax
  483.         push ebx
  484.         push ecx
  485.         push edx
  486.         push ebp
  487.         mov ebx,0
  488.         lodsd ; load, set into registers & store bitmap header
  489.         stosd ;
  490.         mov bx,ax
  491.         shr eax,16
  492.         xchg bx,ax
  493.         shl eax,2   ; nudgets to pixels
  494.         cmp eax,256 ; max 256 pixels wide
  495.         jnbe the_end ; PIC too large for this bitmap compiler
  496.         mov x,eax       ; store width for every plane
  497.         mov yheight,ebx ; store line count
  498.         jmp short comp_entry
  499. newline:
  500.         dec y        ;
  501.         jne inplane  ; if NOT decoded last line, do not switch
  502.         ; else switch plane
  503.         mov byte ptr [edi],0 ; store a switch-plane packet
  504.         inc edi              ;
  505.         jmp the_end ; well, we can stop now.
  506.  
  507.         ; compile this picture
  508. comp_entry:        
  509.         mov eax,yheight       ; get line count
  510.         mov ebx,offset NO_WAY ; lock smart-newlines
  511.         mov y,eax       ; recharge line counter
  512. inplane: ; compile this line
  513.         mov ecx,x   ; reload width counter
  514.         mov ebp,ebx ; store previous packet head position into ebp
  515. skippy_mode:
  516.         mov ebx,edi ; store packet head position
  517.         mov edx,0     ; dh = pix skip counter , dl = pix blit counter
  518.         add edi,2
  519. skip:
  520.         mov al,[esi]
  521.         cmp al,0
  522.         jne xburst
  523.         ; skip this pixels
  524.         inc esi ; to next pix
  525.         inc dh  ; increase skip count
  526. skipped1:        
  527.         dec ecx
  528.         jne skip ; skip if not end of PIC line
  529.         ; END OF PIC LINE WHILE SKIPPING
  530.         test byte ptr [ebp],8 ; had last packet a newline ?
  531.         jnz no_nu
  532.         ; No, we can stuff a newline there
  533.         or byte ptr [ebp],08
  534.         sub edi,2 ; move back this pointer
  535.         jmp newline
  536. no_nu:  ; Yes, it had a newline.
  537.         ; We have to waste one byte
  538.         mov byte ptr [ebx],8 ; newline packet
  539.         dec edi ; we don't need the skip count for a simple newline
  540.         jmp newline
  541.         
  542. burst:  mov al,[esi]
  543.         cmp al,0
  544.         je endburst ; test end of burst
  545. xburst: ; burst of pixels to blit
  546.         inc esi ; to next pix
  547.         mov [edi],al ;store pix
  548.         inc dl  ; increase pixel burst counter
  549.         inc edi ; increase pointer
  550.         dec ecx
  551.         jne burst ; continue bursting pixels if not end ot PIC line
  552.         ; end of line, compose burst packet + newline
  553.         mov al,dl
  554.         and al,3  ; select non-dword count bits
  555.         or al,8   ; set newline bit
  556.         cmp dl,4
  557.         jb blit_d
  558.         or al,4   ; set dword_data bit
  559. blit_d:
  560.         rol dl,2
  561.         and dl,0F0h  ; position dword count into packet
  562.         or dl,al
  563.         mov [ebx],dx ; store packet head
  564.         jmp newline        
  565. endburst:
  566.         ; end of pixel burst, store packet & restart skip counting
  567.         inc esi
  568.         ; compose burst packet without newline
  569.         mov al,dl
  570.         and al,3  ; select non-dword count bits
  571.         ; no newline here, next "skip" can be stuffed here
  572.         cmp dl,4
  573.         jb dblit_d
  574.         or al,4   ; set dword_data bit
  575. dblit_d:
  576.         rol dl,2
  577.         and dl,0F0h  ; position dword count into packet
  578.         or dl,al
  579.         mov [ebx],dx ; store packet head
  580.         
  581.         mov ebp,ebx   ; set previous_packet pointer
  582.         mov edx,0100h ; skip count is already 1
  583.         mov ebx,edi   ; store packet head position
  584.         add edi,2     ; increase data pointer
  585.         jmp skipped1
  586. the_end:
  587.         pop ebp
  588.         pop edx
  589.         pop ecx
  590.         pop ebx
  591.         pop eax
  592.         ret        
  593.                 
  594. code32 ends
  595.  
  596.  END
  597.